package com.qjb.service.impl;

import com.qjb.dao.UserDao;
import com.qjb.entity.User;
import com.qjb.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * 用户业务接口实现层
 * @program: untitled
 * @author: qinjianbao
 * @create: 2020-12-11 17:58
 * @Version: 1.0
 */
public class UserServiceImpl implements UserService {

    private static InputStream inputStream;
    private static UserDao userDao;
    private static SqlSession sqlSession;

    static {

        try {
            //读取SqlMapConfig.xml文件
           inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
            //创建SqlSessionFanctoryBuilder对象
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
            //创建工厂类对象:SqlSessionFactory
            SqlSessionFactory sqlSessionFactroy = sqlSessionFactoryBuilder.build(inputStream);
            //创建执行对象SqlSession
            sqlSession = sqlSessionFactroy.openSession();
            //获取UserDao接口的代理对象
            userDao=sqlSession.getMapper(UserDao.class);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 登录功能
     * @param username 用户名
     * @return 返回该用户
     */
    @Override
    public User login(String username) {

        User user = userDao.login(username);
        if(user!=null){

        }
        return null;
    }
}
